<template>
    <div class="hospital">
        <!-- 左侧导航区域 -->
        <div class="menu">
            <div class="top">
                <el-icon>
                    <HomeFilled />
                </el-icon>
                <span> / 医院信息</span>
            </div>
            <el-menu :default-active="$route.path" :router="true" @select="toSub">
                <el-menu-item index="/hospital/register">
                    <el-icon>
                        <AlarmClock />
                    </el-icon>
                    <span>预约挂号</span>
                </el-menu-item>
                <el-menu-item index="/hospital/detail">
                    <el-icon>
                        <List />
                    </el-icon>
                    <span>医院详情</span>
                </el-menu-item>
                <el-menu-item index="/hospital/notice">
                    <el-icon>
                        <CollectionTag />
                    </el-icon>
                    <span>预约须知</span>
                </el-menu-item>
                <el-menu-item index="/hospital/stop">
                    <el-icon>
                        <Warning />
                    </el-icon>
                    <span>停诊信息</span>
                </el-menu-item>
                <!-- <el-menu-item index="/hospital/search">
                    <el-icon>
                        <Search />
                    </el-icon>
                    <span>查询/取消</span>
                </el-menu-item> -->
            </el-menu>
        </div>
        <!-- 右侧内容展示区——路由组件 -->
        <div class="content">
            <router-view></router-view>
        </div>
    </div>
</template>

<script setup lang="ts">
import {
    CollectionTag,
    AlarmClock,
    List,
    Warning,
    HomeFilled
} from '@element-plus/icons-vue'
import { onMounted } from 'vue';
import { useDetailStore } from '@/store/modules/hospitalDetail';
import { useRouter, useRoute } from 'vue-router'

// 获取一个路由器
const $router = useRouter()
// 获取当前路由相关信息
const $route = useRoute()
// 获取仓库
const detailStore = useDetailStore();

const toSub = (index: string) => {
    // 跳转到对应的二级路由
    $router.push({ path: index, query: { hoscode: $route.query.hoscode } })
}

const { getHospitalDetail, getDepartment } = detailStore

// 组件挂载完成后，通知pinia仓库发请求查询医院详情信息
onMounted(() => {
    getHospitalDetail($route.query.hoscode as string)
    getDepartment($route.query.hoscode as string)
}) 
</script>

<style scoped lang="scss">
.hospital {
    display: flex;

    .menu {
        flex: 2;
        display: flex;
        flex-direction: column;
        align-items: flex-end;

        .top {
            color: #7f7f7f;
            display: flex;
            margin-right: 50px;
        }

        .el-menu {
            width: 150px;
        }
    }

    .content {
        flex: 8;
    }
}
</style>